<template>
  <div class="detail-wapper" v-if="apiStack.price">
    <div class="detail-num">
      <div class="detail-price">￥<span>{{apiStack.price.price.priceText}}</span></div>
      <div class="detail-sales">{{apiStack.vertical.jhs.soldCount}}件已售</div>
    </div>
    <div class="detail-content">
      <div class="detail-title">{{apiStack.item.title}}</div>
      <div class="detail-message">
        <div>{{apiStack.delivery.postage}}</div>
        <div>月销量 {{apiStack.item.sellCount}}</div>
        <div>{{apiStack.delivery.from}}</div>
      </div>
    </div>
  </div>
</template>

<script>
  import { getProductDetail } from 'api/product';

  export default {
    name: 'ProductDetail',
    props: {
      productId: {
        type: String,
        default: ''
      }
    },
    data() {
      return {
        apiStack: {}
      };
    },
    created() {
      this.getDetail(this.productId).then(() => {
        this.$emit('loaded');
      });
    },
    methods: {
      getDetail(id) {
        return getProductDetail(id).then(data => {
          this.apiStack = JSON.parse(data.data.apiStack[0].value);
        });
      }
    }
  };
</script>

<style lang="scss" scoped>
@import "~assets/scss/mixins";

  .detail-wapper {
    width: 100%;
  }

  .detail-num {
    width: 100%;
    height: 45px;
    background-image: linear-gradient(to right, #ef338e, #ef3649 );
    color: #fff;
    padding: 0 15px;
    @include flex-between();
  }

  .detail-num span {
    font-size: 18px;
  }

  .detail-wapper .detail-sales {
    height: 25px;
    width: 85px;
    background-color: #cc2e3e;
    border-radius: 5px;
    line-height: 25px;
    text-align: center;
  }

  .detail-content {
    width: 100%;
    background-color: #fff;
  }

  .detail-title {
    color: #333;
    font-size: 14px;
    border-bottom: 1px solid #eee;
    height: 40px;
    margin: 0 10px;
    @include ellipsis();
    line-height: 40px;
    font-weight: bold;
  }

  .detail-message {
    @include flex-between();
    height: 30px;
    line-height: 30px;
    padding: 0 10px;
    color: #999;
  }

</style>
